package org.opens.util;

import cn.hutool.core.collection.CollectionUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 功能描述
 *
 * @author by zhangyuming
 * @date 2022/9/21
 */
public class SymbolUtil {

    /**
     * 将字符串中的所有指定字符替换为指定字符
     * @param content 待替换的字符串
     * @param symbolsMap 替换规则
     */
    public static String convertChineseSymbolsToEnglishSymbols(String content, Map<String, String> symbolsMap) {
        if (CollectionUtil.isEmpty(symbolsMap)) {
            return content;
        }

        String result = content;

        Set<Map.Entry<String, String>> entries = symbolsMap.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            result = result.replaceAll(entry.getKey(), entry.getValue());
        }

        return result;
    }

    public static void main(String[] args) {
        String str = "varchar2（20）";
        Map<String, String> map = new HashMap<>();
        map.put("）", ")");
        map.put("（", "(");
        System.out.println(convertChineseSymbolsToEnglishSymbols(str, map));
    }

}
